using System.Collections.Generic;

namespace PCC.CQRS
{
    /// <summary>
    /// This class declares an interface for executing an operation.
    /// </summary>
    public class CommandBase
    {
        private readonly List<IReceiver> _receivers;

        public List<IReceiver> Receivers { get { return _receivers; } }

        protected CommandBase()
        {
            _receivers = new List<IReceiver>();
        }

        protected CommandBase(IReceiver receiver)
            : this()
        {
            Receivers.Add(receiver);
        }

        protected CommandBase(IEnumerable<IReceiver> receivers)
            : this()
        {
            Receivers.AddRange(receivers);
        }

        public void Execute()
        {
            foreach (IReceiver receiver in Receivers)
            {
                receiver.Action();
            }
        }
    }
}